namespace SubhadraSolutions.Sharp.Logging
{
    using SubhadraSolutions.Sharp.Logging.Contracts;
    using SubhadraSolutions.Sharp.Utils.Data.Dynamic;
    using SubhadraSolutions.Sharp.Utils.Reflection;
    using System;
    using System.Collections.Generic;
    using System.Linq;

    [Serializable]
    [DbTable("LOGS")]
    public class LogStoreItemDto
    {
        #region Properties

        [DbColumn("ContextValues", false)]
        public string ContextValuesAsAtring
        {
            get;
            set;
        }

        [DbColumn("LogEntry", false)]
        public object LogEntry
        {
            get;
            set;
        }

        [DbColumn("Severity", false)]
        public LogItemSeverity Severity
        {
            get;
            set;
        }

        [DbColumn("ThreadId", false)]
        public int ThreadId
        {
            get;
            set;
        }

        [DbColumn("ThreadName", false)]
        public string ThreadName
        {
            get;
            set;
        }

        [DbColumn("TimeStamp", false)]
        public DateTime TimeStamp
        {
            get;
            set;
        }

        #endregion Properties

        #region Methods

        public static IEnumerable<LogStoreItemDto> CastEnumerable(IEnumerable<LogStoreItem> items)
        {
            return items.Select(CreateFrom);
        }

        public static LogStoreItemDto CreateFrom(LogStoreItem item)
        {
            var dto = new LogStoreItemDto();
            DynamicCopyHelper<LogStoreItem, LogStoreItemDto>.Copy(item, dto);
            return dto;
        }

        #endregion Methods
    }
}